<?php
	include '../class/class.user.php';
	session_start();
	if(isset($_REQUEST['login'])){
		$nip=$_POST['nip'];
		$pass=$_POST['password'];
		$error='';
		$msg=false;
		$dao=new UserDao();

		if(empty($nip) || empty($pass)){
			$error="Username dan Password Harus Diisi";
		}else {
			$user= new User();
			$user->nip=$nip;
			$user->password=$pass;

			if($dao->loginUser($user)){
				
				$user_detail=$dao->getUser($user);
				$cek=$dao->cekAktif($user_detail['id_user']);
				if($cek){
					$msg=true;
					$_SESSION['isLogged']=true;
					$_SESSION['id_user']=$user_detail['id_user'];
					$_SESSION['id_kewenangan']=$user_detail['id_kewenangan'];
				}else{
					$error="User Belum Aktif";
				}
			}else{
				$error="NIP atau Password Salah";
			}
		}
		$data=array(
			'msg'=> $msg,
			'error' => $error	
			);
		echo json_encode($data);
	}

?>